#include <iostream>
#include <stdlib.h>
#include <time.h>

using namespace std;

int takeUsersChoice()
{
    int choice;
    cout << endl << endl;
    cout << "************************************" << endl;
    cout << "****************MENU****************" << endl;
    cout << "************************************" << endl;
    cout << "1. Show numbers A and B" << endl;
    cout << "2. Input values for A and B" << endl;
    cout << "3. Generate random values for A and B" << endl;
    cout << "4. Swap numbers" << endl;
    cout << "5. Calculate the sum of A and B" << endl;
    cout << "6. Calculate difference of A and B" << endl;
    cout << "7. Multiply A and B" << endl;
    cout << "8. Divide A and B" << endl;
    cout << "9. Show the greater from A and B" << endl;
    cout << "10. Show the lesser from A and B" << endl;
    cout << "11. Check if A is equal to B" << endl;
    cout << "0. Exit" << endl;
    cout << "Please choose an action: ";
    cin >> choice;

    return choice;
}

void showNumbers(int num1, int num2)
{
    cout << "A = " << num1 <<endl;
    cout << "B = " << num2 <<endl;
}

void inputNumbers(int &num1, int &num2)
{
    cout << "Input first number: ";
    cin >> num1;
    cout << "Input second number: ";
    cin >> num2;
}

void populateByRandomValues(int &num1, int &num2)
{
    int random = rand() % 201 - 100;
    num1 = random;
    random = rand() % 201 - 100;
    num2 = random;
    cout << "Values of A and B were changed by random numbers" << endl;
}

void swapNumbers(int &num1, int &num2)
{
    int temp = num1;
    num1 = num2;
    num2 = temp;
    cout << "A and B are swapped." << endl;
}

void sumNumbers(int num1, int num2)
{
    int sum = num1 + num2;
    cout <<num1 <<" + " <<num2 <<" = " <<sum <<endl;
}

void subtractNumbers(int num1, int num2)
{
    int diff = num1 - num2;
    cout <<num1 <<" - " <<num2 <<" = " <<diff <<endl;
}

void multiplyNumbers(int num1, int num2)
{
    int product = num1 * num2;
    cout <<num1 <<" X " <<num2 <<" = " <<product <<endl;
}

void divideNumbers(int num1, int num2)
{
    if(num2 == 0)
    {
        cout << "Cannot divide by 0" <<endl;
    }
    else
    {
        int product = num1 / num2;
        cout <<num1 <<" : " <<num2 <<" = " <<product <<endl;
    }
}

void findGreater(int num1, int num2)
{
    if(num1 > num2)
    {
        cout << "A is greater than B" <<endl;
    }
    if(num2 > num1)
    {
        cout << "B is greater than A" <<endl;
    }
    if( num1 == num2)
    {
        cout << "A and B are equel" <<endl;
    }
}

void findLesser(int num1, int num2)
{
    if(num1 < num2)
    {
        cout << "A is less than B" <<endl;
    }
    if(num2 < num1)
    {
        cout << "B is less than A" <<endl;
    }
    if( num1 == num2)
    {
        cout << "A and B are equel" <<endl;
    }
}

void checkEqual(int num1, int num2)
{
    if(num1 == num2)
    {
        cout << "A and B are EQUAL!" <<endl;
    }
    else
    {
        cout << "A and B are NOT EQUAL" <<endl;
    }
}

int main()
{
    int timeNow = time(NULL);
    srand(timeNow);
    int choice;
    int a = 0;
    int b = 0;
    do
    {
        choice = takeUsersChoice();
        switch(choice)
        {
            case 0:
                break;
            case 1:
                showNumbers(a, b);
                break;
            case 2:
                inputNumbers(a, b);
                break;
            case 3:
                populateByRandomValues(a, b);
                break;
            case 4:
                swapNumbers(a, b);
                break;
            case 5:
                sumNumbers(a, b);
                break;
            case 6:
                subtractNumbers(a, b);
                break;
            case 7:
                multiplyNumbers(a, b);
                break;
            case 8:
                divideNumbers(a, b);
                break;
            case 9:
                findGreater(a, b);
                break;
            case 10:
                findLesser(a, b);
                break;
            case 11:
                checkEqual(a, b);
                break;
            default:
                cout << "Invalid choice!" << endl;
                break;
        }
    } while (choice != 0);

    return 0;
}
